/*
 * 下拉菜单
 *
 * items为示例数据集
 * title: 标题
 * id: 选项标识
 * 是否选中
 *
 * */

define(['backbone'], function(Backbone) {
    var Model = Backbone.Model.extend({
        defaults: function() {
            return {
                'title': 'test'
            };
        },
        destroy:function(){
            this.trigger('destroy');
        }
    });


    var collections = Backbone.Collection.extend({
        model: Model,
        url: "./api/showcase",
        state: {},
        initialize:function(){
            this.reset(items);

        },
        fetch: function() {

        },

        addItem: function(){
            for (var i = 0; i < this.pageSize; i++) {
                var position = this.curPageIndex * this.pageSize + i;
                if(items.length > position ){
                    this.add(new Model(items[position]));
                }else{
                    break;
                }
            }

        },

        curPageIndex: 0,
        pageSize: 10,
        getNextPage: function() {
            this.curPageIndex += 1;
            this.addItem();
        },
        hasNextPage: function() {
            return items.length/ this.pageSize > this.curPageIndex;
        },
        getFirstPage: function() {
            this.curPageIndex = 0;
            this.addItem();
        }
    });

    return collections;
});
